/*
 * @Author: wuzhouhai wzh200x@126.com
 * @Date: 2024-05-16 14:38:21
 * @LastEditors: wuzhouhai wzh200x@126.com
 * @LastEditTime: 2024-12-04 17:53:54
 * @FilePath: \dwys_web\extensions\phoenix-plugin-client\assets\core\defines\error.local.define.ts
 * @Description:
 */
export enum ErrorLocalCode {
    SUCCESS = 0,
    UNKNOWN_ERROR = -999,
    ACCOUNT_NOT_CREATE,
    ACCOUNT_NAME_EMPTY,
    ACCOUNT_PASSWORD_EMPTY,
    AVATAR_NOT_CREATE,
    PLATFORM_NOT_SUPPORT,
    SERVER_NOT_SELECT,
    SERVER_IS_NULL,
    SERVER_INDEX_OUT_OF_RANGE,
    SERVER_NOT_FOUNT,
    PLATFORM_LOGIN_FAIED,
    REQUEST_FAILED,
    RETRY_SWITCH_DOMAIN_LIMIT,
    MOUDLE_NOT_EXSIT,
    REQUEST_TIMEOUT,
}

export enum ErrorLocalCodeDescription {
    SUCCESS = '',
    UNKNOWN_ERROR = '未知错误',
    ACCOUNT_NOT_CREATE = '账号实体未创建',
    ACCOUNT_NAME_EMPTY = '账号名为空',
    ACCOUNT_PASSWORD_EMPTY = '账号密码为空',
    AVATAR_NOT_CREATE = '角色实体未创建',
    PLATFORM_NOT_SUPPORT = '平台不支持',
    SERVER_NOT_SELECT = '未选择服务器',
    SERVER_IS_NULL = '服务器列表为空',
    SERVER_INDEX_OUT_OF_RANGE = '服务器索引无效',
    SERVER_NOT_FOUNT = '服务器未找到',
    PLATFORM_LOGIN_FAIED = '平台登录失败',
    REQUEST_FAILED = '请求失败,无法连接服务器',
    RETRY_SWITCH_DOMAIN_LIMIT = '重试次数过多,切换域名',
    MOUDLE_NOT_EXSIT = '模块不存在',
    REQUEST_TIMEOUT = '请求超时',
}

export function makeLocalError(errorCode: ErrorLocalCode, errorDescription?: ErrorLocalCodeDescription): object {
    return { message: errorDescription, code: errorCode };
}

export function getLocalErrorDescription(errorCode: ErrorLocalCode): ErrorLocalCodeDescription {
    switch (errorCode) {
        case ErrorLocalCode.ACCOUNT_NOT_CREATE:
            return ErrorLocalCodeDescription.ACCOUNT_NOT_CREATE;
        case ErrorLocalCode.ACCOUNT_NAME_EMPTY:
            return ErrorLocalCodeDescription.ACCOUNT_NAME_EMPTY;
        case ErrorLocalCode.ACCOUNT_PASSWORD_EMPTY:
            return ErrorLocalCodeDescription.ACCOUNT_PASSWORD_EMPTY;
        case ErrorLocalCode.AVATAR_NOT_CREATE:
            return ErrorLocalCodeDescription.AVATAR_NOT_CREATE;
        case ErrorLocalCode.PLATFORM_NOT_SUPPORT:
            return ErrorLocalCodeDescription.PLATFORM_NOT_SUPPORT;
        case ErrorLocalCode.SERVER_NOT_SELECT:
            return ErrorLocalCodeDescription.SERVER_NOT_SELECT;
        case ErrorLocalCode.SERVER_IS_NULL:
            return ErrorLocalCodeDescription.SERVER_IS_NULL;
        case ErrorLocalCode.SERVER_INDEX_OUT_OF_RANGE:
            return ErrorLocalCodeDescription.SERVER_INDEX_OUT_OF_RANGE;
        case ErrorLocalCode.SERVER_NOT_FOUNT:
            return ErrorLocalCodeDescription.SERVER_NOT_FOUNT;
        case ErrorLocalCode.PLATFORM_LOGIN_FAIED:
            return ErrorLocalCodeDescription.PLATFORM_LOGIN_FAIED;
        default:
            return ErrorLocalCodeDescription.UNKNOWN_ERROR;
    }
}
